<template>
  <div id="app">
    <!-- 顶部模块 -->
    <Topbar :key="topBarKeyValue"></Topbar>

    <!-- 头部模块 -->
    <Header></Header>

    <router-view />
    <!-- 底部模块 -->
    <Footer></Footer>
    <Login v-show="isShowLoginModal"></Login>
    <transition>
      <Toast v-show="isShowToast"></Toast>
    </transition>
  </div>
</template>

<script>
import Topbar from "@/components/Topbar";
import Header from "@/components/Header";
import Footer from "@/components/Footer";
//导入Login组件
import Login from "@/components/Login.vue";

import Toast from "@/components/Toast.vue";

import { mapState } from "vuex";

import { JingpinAPI } from "@/request/api";

export default {
  data(){
    return{
      topBarKeyValue:0
    }
  },
  components: {
    Topbar,
    Header,
    Footer,
    Login,
    Toast,
  },
  computed: {
    ...mapState({
      isShowLoginModal: (sate) => sate.ShowLogin.isShowLoginModal,
      isShowToast: (state) => state.showToast.isShowToast,
    }),
  },
  created() {
    JingpinAPI().then((res) => {
      console.log(res);
    });
  },
  watch:{
    // 监听路由的变化
    '$route.path':{
      handler(newVal,oldVal){
        if(newVal != oldVal){
          this.topBarKeyValue++;
        }
      }
    }
  }
};
</script>


<style lang="less">
#app {
  /* 入场的起始状态 = 离场的结束状态 */
  .slide-enter,
  .slide-leave-to {
    opacity: 0;
  }

  .slide-enter-active,
  .slide-leave-active {
    transition: opacity 0.3s linear;
  }

  .slide-enter-to,
  .slide-leave {
    opacity: 1;
  }
}
</style>
